home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacGofer 0.22d / MacGofer Sources / mac_StrInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-06  |  2.5 KB  |  103 lines  |  [TEXT/MPS ]

  1. /*****************************************************************************
  2.  
  3.   mac_StrInit.c:  Copyright (c) Kevin Hammond 1993.   All rights reserved.
  4.   
  5.   This module reads strings from the Gofer resource fork.
  6.  
  7. *****************************************************************************/
  8.  
  9.  
  10. #include "mac.h"
  11.  
  12. #pragma segment StrInit
  13.  
  14. extern char *safemalloc();
  15.  
  16. /* GoferVersionString is allocated in getresstring() */
  17.  
  18. char *GoferVersionString;
  19.  
  20. extern char     *PreludeName, *PrefsName;
  21. extern unsigned  ExtraStack;
  22.  
  23.  
  24. char *getresstring();
  25.  
  26. /*
  27.     InitResData reads all initialisation strings from the resource fork.
  28.     These are currently:
  29.     
  30.     Res_MinSize_String    Minimum Startup Size
  31.     Res_StackSize_String    How much extra C stack to allow (0=>default)
  32.     Res_PreludeName_String    What the Prelude's called
  33.     Res_PrefName_String    What the Preference File's called
  34.     Res_Version_String    Gofer Version
  35. */
  36.  
  37.  
  38. InitResData()
  39. {
  40.   char *GoferSizeString, *GoferStackString;
  41.  
  42.   /* Version */
  43.   GoferVersionString = getresstring(Res_Version_String);
  44.   if(GoferVersionString == NIL)
  45.     GoferVersionString = "??.??";
  46.  
  47.   /* Minimum Macintosh heap to run in, even without MultiFinder */
  48.   GoferSizeString = getresstring(Res_MinSize_String);
  49.   if(GoferSizeString == NIL || (MinMemSize = atoi(GoferSizeString))==0)
  50.     MinMemSize = DEFAULT_MIN_MEM_SIZE;
  51.  
  52.   /* Extra Stack to allocate, 0 means use the default algorithm */
  53.   GoferStackString = getresstring(Res_StackSize_String);
  54.   if(GoferStackString != NIL)
  55.      ExtraStack = atoi(GoferStackString);
  56.  
  57.   /* The name of the Prelude file */
  58.   PreludeName = getresstring(Res_PreludeName_String);
  59.   if(PreludeName==NIL)
  60.     PreludeName = "";
  61.  
  62.   /* The name of the Prelude file */
  63.   PrefsName = getresstring(Res_PrefsName_String);
  64.   if(PrefsName==NIL)
  65.     PrefsName = DEFAULT_PREFS_NAME;
  66.  
  67.   /* Free the local strings if malloc() is known to have been used */ 
  68.   if(GoferSizeString!=NIL)
  69.     free(GoferSizeString);
  70.  
  71.   if(GoferStackString!=NIL)
  72.     free(GoferStackString);
  73. }
  74.  
  75.  
  76. /*
  77.     Get resource 'STR ' id into the string pointer s.
  78.     s is set to NIL if no such resource exists.
  79.     Otherwise a new C string is allocated, and the resource copied.
  80.     This lets us free the string later if required.
  81. */
  82.  
  83. char *getresstring(id)
  84. int id;
  85. {
  86.   Handle h = GetResource('STR ',id);
  87.  
  88.   if(h == NIL)
  89.     return(NIL);
  90.   else
  91.     {
  92.       char *s = safemalloc((int)(**(char **)h)+1);
  93.  
  94.       /* Lock and copy h: locked in case pstrcopy's in a different segment */
  95.       HLock(h);
  96.       pstrcopy((char *)*h,s);
  97.       HUnlock(h);
  98.  
  99.       p2cstr(s);
  100.       return(s);
  101.     }
  102. }
  103.